<?php

class genericoModel extends Model
{
    public function __construct() {
        parent::__construct();
        
    }
    
    public function query($tabla, $campos,$condicion=false)
    {
        if (@$condicion) {
        
        $usuario = $this->_db->query("select ".$campos." from ".$tabla." where ".$condicion);
      //echo "select ".$campos." from ".$tabla." where ".$condicion;
        return $usuario;
        }else{
        
        $usuario = $this->_db->query("select ".$campos." from ".$tabla);
        return $usuario;
        }
    }
    
    public function insertar($tabla, $campos,$camposIn,$valor)
    {
        
       // $usuario = $this->_db->query("INSERT INTO ".$tabla." (".$campos.") VALUES (".$camposIn.")");
        //echo "INSERT INTO ".$tabla." (".$campos.") VALUES (".$camposIn.")";
        //return $usuario;
       try {
           return  $this->_db->prepare("INSERT INTO ".$tabla."  (".$campos.") VALUES (".$camposIn.")")->execute($valor);
} catch(PDOException $e) {
    echo "Exception caught: $e";
}
                
                
               
    }
    
     public function modificar($tabla, $campos,$condicion) {
        try {
             //echo   "UPDATE ". $tabla ." SET  ".$campos." WHERE ".$condicion;
            return $this->_db->prepare("UPDATE ". $tabla ." SET  ".$campos." WHERE ".$condicion)->execute();
        } catch (PDOException $e) {
            echo "Exception caught: $e";
        }
    }
    public function eliminar($tabla,$campo,$condicion){
        try {
        //echo " DELETE FROM ". $tabla ." WHERE  ".$campo."=".$condicion;
        //exit();
        return $this->_db->prepare("DELETE FROM ". $tabla ." WHERE  ".$campo."=".$condicion)->execute();
        }catch (PDOException $e) {
            echo "Exception caught: $e";
        }
    }
    
    function uuid() {
        $data = 'select public.uuid_generate_v1() as uuid';
         $query = $this->_db->query($data);
         
         foreach ($query as $row){
                $uuid = $row['uuid'];
        }
        return $uuid;
    }
}

?>
